<template>
  <div>
    <el-form ref="form" :model="form" label-width="90px" class="form-flex">
      <el-row>
        <template v-for="(row,index) in communityParamList">
          <el-col :span="24">
            <el-form-item :label="row.paramName" :prop="row.paramKey">
              <l-form-item
                v-model="form[row.paramKey]"
                :type="row.type"
                :typeCode="row.typeCode"
                :placeholder="row.placeholder"
                @cv="(v)=>changeParam(row,v)"
                clearable
              />
            </el-form-item>
          </el-col>
        </template>
      </el-row>
    </el-form>
  </div>
</template>

<script>
  import { listCommunityParam,saveOrUpdate } from "@/api/property/communityParam"
  export default {
    name: "communityParam",
    data(){
      return {
        communityParamList:[
          {paramName:"账单生成日",paramKey:"bill_create_day"},
          {paramName:"住户邀请",paramKey:"house_invite",type:"select",typeCode:'house_invite'},
        ],
        form:{

        }
      }
    },
    watch: {
      "currentNode"(v) {
        this.initForm()
      }
    },
    created() {
      this.initForm()
    },
    methods:{
      initForm(){
        this.reset()
        listCommunityParam({communityId:this.currentNode.id}).then(res=>{
            let listData = res.rows
            for(let i in listData){
              let row = listData[i]
              if(this.form.hasOwnProperty(row.paramKey)){
                this.form[row.paramKey] = row.paramValue
              }
            }
        })
      },
      // 表单重置
      reset() {
        this.form = {
          bill_create_day: null,
          house_invite:null
        };
        this.resetForm("form");
      },
      changeParam(row,v){
        let param = {
          paramName: row.paramName,
          paramKey: row.paramKey,
          paramValue: v,
          communityId:this.currentNode.id
        }
        saveOrUpdate(param).then(res=>{

        })
      }
    },
    props: {
      currentNode: {
        type: Object,
        default: () => {
        }
      },
    }
  }
</script>

<style scoped>

</style>
